package com._520it.wms.web.controller;

import com._520it.wms.domain.Department;
import com._520it.wms.query.PageResult;
import com._520it.wms.query.QueryObject;
import com._520it.wms.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by dd on 2017/11/15.
 */
@Controller
@RequestMapping("department")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("list")
    public String list(Model model, QueryObject qo){
        model.addAttribute("departments",departmentService.query(qo));
        return "department/list";
    }

    @RequestMapping("input")
    public String input(Long id,Model model){
        if(id!=null) {
            model.addAttribute("department", departmentService.get(id));
        }
        return "department/input";
    }

    @RequestMapping("delete")
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list.do";
    }

    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list.do";
    }
}
